package com.itheima.app.controller;

import com.itheima.app.manager.SettingManager;
import com.itheima.domain.db.Notification;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class SettingController {

    @Autowired
    private SettingManager settingManager;

    //保存或者修改陌生人问题
    @PostMapping("/users/questions")
    public void saveOrUpdateQuestion(@RequestBody Map<String,String> map) {
        //获取用户设置的陌生人问题
        String content = map.get("content");
        settingManager.saveOrUpdateQuestion(content);
    }

    //保存或者修改通知设置
    @PostMapping("/users/notifications/setting")
    public void saveOrUpdateNotification(@RequestBody Notification notification) {
        settingManager.saveOrUpdateNotification(notification);
    }

    //查询黑名单列表
    @GetMapping("/users/blacklist")
    public PageBeanVo findBlackList(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize) {

        return settingManager.findBlackList(page,pagesize);
    }

    //移除黑名单
    @DeleteMapping("/users/blacklist/{blackUserId}")
    public void deleteBlackList(@PathVariable("blackUserId") Long blackUserId) {
        settingManager.deleteBlackList(blackUserId);
    }


    /**
     * 修改手机号 - 1 发送短信验证码
     */
    @PostMapping("/users/phone/sendVerificationCode")
    public void updateTelephoneSendCode(){
        //直接调用settingManager
        settingManager.updateTelephoneSendCode();
    }

    /**
     * 修改手机号 - 2 校验验证码
     * @return
     */
    @PostMapping("/users/phone/checkVerificationCode")
    public ResponseEntity checkVerificationCode(@RequestBody Map<String,String> map){
        //1.获取参数，验证码
        String verificationCode = map.get("verificationCode");
        //2.调用settingsManager
        return settingManager.checkVerificationCode(verificationCode);
    }

    /**
     * 修改手机号 - 3 保存
     */
    @PostMapping("/users/phone")
    public void updatePhone(@RequestBody Map<String,String> map) {
        //1.获取手机号
        String phone = map.get("phone");
        //2.调用settingsManager
        settingManager.updatePhone(phone);
    }


}
